/*

/// disco.js v0.2.1a ///

package of all disco client library TypeScript definitions
based on the following files in this order:

* disco.core.js
* disco.model.js
* disco.model.helper.js
* disco.web.js
* disco.ontology.js

Note that you have to also include jQuery, Knockout JS and DataJS to get this work!
(Tested with jQuery v1.8.2 and 2.0.1, Knockout v2.2.0 and 2.3.0 and DataJS v1.1.1beta2 and 1.1.1, also included in this folder)

Created with TypeScript (see http://typescriptlang.org/ and *.ts files)

(c) by AG Meinungsfindungstool of the Pirate Party Germany

*/

/// <reference path="../../typings/jquery/jquery.d.ts" />
/// <reference path="../../typings/knockout/knockout.d.ts" />
declare module disco.core {
    class DataManager<T> {
        private data;
        constructor();
        public get(): T;
        public set(value: T): T;
    }
}
declare module disco {
    class Namespace {
        static remove(object: string): string;
    }
    class Collections {
        static contains<T>(collection: T[], predicate: (item: T, index: number) => boolean): boolean;
        static where<T>(collection: T[], predicate: (item: T, index: number) => boolean): T[];
        static single<T>(collection: T[], predicate: (item: T, index: number) => boolean): T;
        static nullableSingle<T>(collection: T[], predicate: (item: T, index: number) => boolean): T;
        static select<T>(collection: T[], selector: (item: T) => any[]): any[];
        static implode(collection: any[], delimiter: string): string;
    }
    class Callbacks {
        static batch(batch: {
            (onReady: any): void;
        }[], onFinish?: () => void): void;
        static allAtOnce(callbacks: {
            (onReady: any): void;
        }[], onFinish?: () => void): void;
    }
    class Type {
        static get(variable): string;
    }
    class Filters {
        static valueToOdata(value: any): string;
    }
}
declare module disco.model.helper {
    class DataContextManager {
        private dataContext;
        constructor(dataContext: model.DataContext);
        public getDataContext(): model.DataContext;
        public setDataContext(context: model.DataContext): void;
        public getMetadata(): any;
        public generateEntityModel(): void;
        public generateEntitySets(): void;
        public generateEntityTypes(): void;
        private generateBasicEntityTypes();
        private applyBaseTypes();
        private addNavigationToEntityProperties();
        private getEntityTypesMetadata();
        private getAssociationsMetadata();
        private getEntitySetsMetadata();
        private getMetadataServices();
    }
    class EntitySetManager extends disco.core.DataManager<model.EntitySet> {
        public add(entity: model.Entity): void;
    }
    class EntityManager extends disco.core.DataManager<model.Entity> {
        private context;
        constructor(context: model.DataContext);
        public fromRawEntity(rawEntity): model.Entity;
    }
}
declare module disco.web {
    class Requests {
        static loadOntologyMetadata(url: string, success: (metadata: any) => void, error?: (error: any) => void): void;
        static loadOntologyContent(url: string, success: (data: any) => void, error?: (error: any) => void): void;
        static addEntity(entitySetUrl: string, propertyValues: any, success: (data: any) => void, error?: (error: any) => void): void;
        static removeEntity(entityUrl: string, success: (data: any) => void, error?: (error: any) => void): void;
        static addEntityConnection(entityUrl: string, propertyUrl: string, valueUrl: string, success: (data: any) => void, error?: (error: any) => void): void;
        static removeEntityConnection(entityUrl: string, propertyUrlWithKey: string, success: (data: any) => void, error?: (error: any) => void): void;
    }
}
declare module disco {
    class Ontology {
        public dataContext: disco.model.DataContext;
        private serviceUri;
        constructor(serviceUri: string);
        public isInitialized(): boolean;
        public init(success: (context: disco.model.DataContext) => void, error: (error: any) => void): void;
        public getEntityById(type: disco.model.EntityType, id: number, success: (entity: disco.model.Entity) => void, error: (error: any) => void): void;
        public getEntityByPath(path: string, success: (entity: disco.model.Entity) => void, error: (error: any) => void): void;
        public getEntitiesByPath(path: string, success: (entities: disco.model.Entity[]) => void, error: (error: any) => void): void;
        public getEntitiesByUrl(url: string, success: (entities: disco.model.Entity[]) => void, error?: (error: any) => void): void;
        private registerFromRawEntity(rawEntity);
        public getEntitiesByTemplate(template: any, success: (entities: disco.model.SubEntity[], completeEntities: disco.model.Entity[]) => void, error?: (err: any) => void, url?: string): void;
        public addEntity(entityTemplate: any, success: (e: disco.model.Entity) => void, error: (e: any) => void): void;
        public removeEntity(entityType: disco.model.EntityType, entityId: any, success: () => void, error: (error: any) => void): void;
        public removeEntityByPath(path: string, success: () => void, error: (error: any) => void): void;
        public removeEntityByUrl(url: string, success: () => void, error: (error: any) => void): void;
        public addConnection(entityType: disco.model.EntityType, entityId: any, property: disco.model.EntityProperty, valueId: any, success: () => void, error: (error: any) => void): void;
        public removeConnection(entityType: disco.model.EntityType, entityId: any, property: disco.model.EntityProperty, valueId: any, success: () => void, error: (error: any) => void): void;
        public clearCache(): void;
    }
}
declare module disco.model {
    interface DataServices {
        schema: any[];
    }
    class Metadata {
        public version: string;
        public dataServices: DataServices;
    }
    class DataContext {
        public metadata: Metadata;
        public serviceUri: string;
        public entityTypes: any;
        public entitySets: any;
        public entityType(name: string, value?: EntityType): EntityType;
        public entitySet(typeName: string, value?: EntitySet): EntitySet;
    }
    class EntityType {
        public name: string;
        public entitySet: EntitySet;
        public properties: EntityProperty[];
        public navigationProperties: NavigationProperty[];
        public baseType: EntityType;
        public metadata: any;
        public toString(): string;
        public useToStringForStringify: boolean;
    }
    class EntityProperty {
        public name: string;
        public isInherited: boolean;
        public isKey: boolean;
        public isNullable: boolean;
        public isMany: boolean;
        public typeString: string;
        public type: EntityType;
        public isNavigation: boolean;
        public toString(): string;
        public useToStringForStringify: boolean;
    }
    class NavigationProperty {
        public name: string;
        public inherited: boolean;
        public from: AssociationEnd;
        public to: AssociationEnd;
    }
    class AssociationEnd {
        public role: string;
        public type: string;
        public multiplicity: string;
    }
    class EntityCollection {
        public rows: KnockoutObservableArray<Entity>;
    }
    class EntitySet extends EntityCollection {
        public name: string;
        public type: EntityType;
    }
    class Entity {
        public type: EntityType;
        public properties: any;
        public prop(name: string, value?: PropertyValue): PropertyValue;
        public isEntity: boolean;
    }
    class PropertyValue {
        constructor(prop?: PropertyValue);
        public property: EntityProperty;
        public prop(name: string): PropertyValue;
        public url: string;
        public value: any;
    }
    class OntologyModel {
        private dataContext;
        public getDataContext(): KnockoutObservable<DataContext>;
        public load(serviceUri: string, success?: (ontology: OntologyModel) => void): void;
    }
    class EntityTypeManager {
        private entityType;
        constructor(entityType?: EntityType);
        public getEntityType(): EntityType;
        public setEntityType(value?: EntityType): EntityType;
        public each(types: EntityType[], callback: (typeMgr: EntityTypeManager, index: number, types: EntityType[]) => void): void;
        public generateSimpleProperties(metaEntityType: any, associations: any[]): void;
        public applyBaseType(context: DataContext): void;
        public addNavigationToEntityProperties(context: DataContext): void;
    }
    class EntityPropertyManager {
        private entityProperty;
        constructor(entityProperty?: EntityProperty);
        public getEntityProperty(): EntityProperty;
        public setEntityProperty(entityProperty?: EntityProperty): EntityProperty;
        public generateEntityProperty(metaProperty: any, keyPropertyName: string): void;
        public fromNavigationProperty(navigationProperty: NavigationProperty, context: DataContext): EntityProperty;
        public copyProperty(property: EntityProperty): EntityProperty;
        public copyProperties(properties: EntityProperty[]): EntityProperty[];
    }
    class NavigationPropertyManager {
        private navigationProperty;
        constructor(navigationProperty?: NavigationProperty);
        public getNavigationProperty(): NavigationProperty;
        public setNavigationProperty(property?: NavigationProperty): NavigationProperty;
        public generateNavigationProperty(metaProperty: any, metaAssociations: any[]): void;
        public copyProperty(property: NavigationProperty): NavigationProperty;
        public copyProperties(properties: NavigationProperty[]): NavigationProperty[];
    }
    var stringifyReplacer: (key: any, value: any) => any;
    class SubEntity {
        constructor(entity?: Entity);
        private _entity;
        public entity: (val?: Entity) => Entity;
        public props: any;
        public prop(name: string, val?: PropertyValue): PropertyValue;
        public type: EntityType;
        public isEntity: boolean;
    }
}
